/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.ufba.lasid.v1.jitclouds.mda.datatypes.ft;

import br.ufba.lasid.v1.jitclouds.mda.datatypes.IConfiguration;

/**
 *
 * @author aliriosa
 */
public class BasicFailoverDeployer implements IFailoverDeployer{

    private IConfiguration configuration = null;
    private String idDeployer = null;
    private String dsDeployer = null;
    private Long period = null;
    
    @Override
    public void install(IReplicableList replicas) {
        if(replicas != null && replicas.size() == 2){
            IReplicable primary = replicas.getPrimary();
            IReplicable backup = replicas.get(0);
            
            if(primary == backup){
                backup = replicas.get(1);
            }                                    
            
            execute("installfailover", primary, backup);
        }        
    }

    public IConfiguration getConfiguration() {
        return configuration;
    }

    public void setConfiguration(IConfiguration configuration) {
        this.configuration = configuration;
    }
    
    @Override
    public void execute(String action, IReplicable primary, IReplicable backup){
         //Do nothing
    }
    
    protected String getCommand(String action){
        return getConfiguration().get(action);        
    }

    @Override
    public void setID(String ID) {
        this.idDeployer = ID;
    }

    @Override
    public String getID() {
        return this.idDeployer;
    }

    @Override
    public void setDescription(String description) {
        this.dsDeployer = description;
    }

    @Override
    public String getDescription() {
        return this.dsDeployer;
    }

    @Override
    public Long getPeriod() {
        return this.period;
    }

    @Override
    public void setPeriod(Long period) {
        this.period = period;
    }

    @Override
    public void install(IReplicable primary, IReplicable backup) {
        execute("installfailover", primary, backup);
    }
    
}
